package com.yiyuan.app.controller;

import com.guaike.core.entity.result.Result;
import com.yiyuan.app.service.PlayService;
import com.yiyuan.app.entity.param.*;
import com.yiyuan.app.entity.result.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/play")
@Api(tags = "游戏相关接口组")
@AllArgsConstructor
public class PlayController {

    private final PlayService playService;

    @GetMapping("/roomList")
    @ApiOperation(value = "潮玩房间列表")
    public Result<List<BaseRoomVO>> roomList(@Valid RoomListDTO param) {
        return playService.roomList(param);
    }

    @GetMapping("/intoRoom")
    @ApiOperation(value = "进入房间")
    public Result<RoomVO> intoRoom(@ApiParam(value = "房间id", required = true) @RequestParam("roomId") Long roomId) throws IOException {
        return playService.intoRoom(roomId);
    }

    @PostMapping("/startGame")
    @ApiOperation(value = "开始游戏")
    public Result<Boolean> startGame(@RequestBody @Valid StartGameDTO param) {
        return playService.startGame(param);
    }

    @GetMapping("/checkCanPlay")
    @ApiOperation(value = "校验自己是否可以游戏")
    public Result<Boolean> checkCanPlay(@ApiParam(value = "房间id", required = true) @RequestParam("roomId") Long roomId
            , @ApiParam(value = "机位编号", required = true) @RequestParam("positionNo") String positionNo) {
        return playService.checkCanPlay(roomId, positionNo);
    }

    @PostMapping("/exitGame")
    @ApiOperation(value = "退出游戏")
    public Result<Boolean> exitGame(@RequestBody @Valid ExitGameDTO param) throws Exception {
        return playService.exitGame(param);
    }

    @PostMapping("/exitOccupyGame")
    @ApiOperation(value = "退出推币机畅玩游戏开启新游戏")
    public Result<Boolean> exitOccupyGame(@RequestBody @Valid ExitGameDTO param) {
        return playService.exitOccupyGame(param);
    }

//    @PostMapping("/startBattle")
//    @ApiOperation(value = "开始挑战")
//    public Result<Boolean> startBattle(@RequestBody @Valid StartBattleDTO param) {
//        return playService.startBattle(param);
//    }

    @GetMapping("/checkPushCoins")
    @ApiOperation(value = "校验是否可投币")
    public Result<Boolean> checkPushCoins(@ApiParam(value = "房间id", required = true) @RequestParam("roomId") Long roomId, @ApiParam(value = "投币数量", required = true) @RequestParam("count") Integer count) {
        return playService.checkPushCoins(roomId, count);
    }

    @GetMapping("/findPlayPinecone")
    @ApiOperation(value = "游戏中获取松果数量")
    public Result<PlayPineDataVO> findPlayPinecone(@ApiParam(value = "房间id", required = true) @RequestParam("roomId") Long roomId) {
        return playService.findPlayPinecone(roomId);
    }

    @PostMapping("/reportRepair")
    @ApiOperation(value = "报修房间")
    public Result<Boolean> reportRepair(@RequestBody @Valid BaseRoomIdDTO param) throws IOException {
        return playService.reportRepair(param);
    }

    @GetMapping("/findAutoInfo")
    @ApiOperation(value = "获取挂机信息")
    public Result<AutoVO> findAutoInfo(@ApiParam(value = "房间id", required = true) @RequestParam("roomId") Long roomId) {
        return playService.findAutoInfo(roomId);
    }

    @GetMapping("/findPrizeConfig")
    @ApiOperation(value = "获取赏金配置")
    public Result<List<PrizeConfigVO>> findPrizeConfig(@ApiParam(value = "房间id", required = true) @RequestParam("roomId") Long roomId) {
        return playService.findPrizeConfig(roomId);
    }

    @PostMapping("/submitPrize")
    @ApiOperation(value = "推币机提交赏金")
    public Result<Boolean> submitPrize(@RequestBody @Valid SubmitPrizeDTO param) throws IOException {
        return playService.submitPrize(param);
    }

    @GetMapping("/findCwPrizeConfig")
    @ApiOperation(value = "获取潮玩奖励配置")
    public Result<List<CwPrizeConfigVO>> findCwPrizeConfig() {
        return playService.findCwPrizeConfig();
    }

    @GetMapping("/findCwRecord")
    @ApiOperation(value = "获取潮玩记录")
    public Result<List<PrizeRecordVO>> findCwRecord() {
        return playService.findCwRecord();
    }

    @GetMapping("/findMyCwRecord")
    @ApiOperation(value = "获取我的潮玩记录")
    public Result<List<BasePrizeRecordVO>> findMyCwRecord() {
        return playService.findMyCwRecord();
    }

    @GetMapping("/getLookPersonCount")
    @ApiOperation(value = "获取围观人数")
    public Result<Long> getLookPersonCount(@ApiParam(value = "房间id", required = true) @RequestParam("roomId") Long roomId) {
        return playService.getLookPersonCount(roomId);
    }

    @GetMapping("/getTotalPineNut")
    @ApiOperation(value = "获取推币机本场累计获得松子数（包机时返回包机松果数）")
    public Result<Long> getTotalPineNut(@ApiParam(value = "房间id,返回结果是null则不显示提示", required = true) @RequestParam("roomId") Long roomId) {
        return playService.getTotalPineNut(roomId);
    }

    @GetMapping("/getTotalPineNutNew")
    @ApiOperation(value = "获取推币机本场累计获得松子数（包机时返回包机松果数）")
    public Result<PlayGetDataVO> getTotalPineNutNew(@ApiParam(value = "房间id,返回结果是null则不显示提示", required = true) @RequestParam("roomId") Long roomId) {
        return playService.getTotalPineNutNew(roomId);
    }

}
